package com.tangsm.spring.boot.swagger3.mapper;

import com.tangsm.spring.boot.swagger3.domain.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 学生信息数据持化
 * <p>mybatis 注解实现</p>
 * @author tangsm
 * @date 2021-07-23
 */
@Mapper
public interface StudentMapper {
    /**
     * 新增
     * @param student 学生信息
     * @return 成功数
     */
    @Insert("insert into student(sno,sname,ssex) values(#{sno},#{sname},#{ssex})")
    int add(Student student);

    /**
     * 修改
     * @param student 学生信息
     * @return 成功数
     */
    @Update("update student set sname=#{sname},ssex=#{ssex} where sno=#{sno}")
    int update(Student student);

    /**
     * 删除
     * @param sno 学号
     * @return 成功数
     */
    @Delete("delete from student where sno=#{sno}")
    int deleteBySno(String sno);

    /**
     * 根据主键查询
     * @param sno 学号
     * @return 学生信息
     */
    @Select("select * from student where sno=#{sno}")
    @Results(id = "student",value= {
            @Result(property = "sno", column = "sno", javaType = String.class),
            @Result(property = "sname", column = "sname", javaType = String.class),
            @Result(property = "ssex", column = "ssex", javaType = String.class)
    })
    Student queryBySno(String sno);
}
